/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2025-02-26
 * Time: 11:45
 */
public class test2 {
    /**
     * LeetCode 844 比较含退格的字符串
     */

    public boolean backspaceCompare(String s, String t) {
        return changeStr(s).equals(changeStr(t));
    }

    public String changeStr(String s){
        StringBuffer ret = new StringBuffer();
        for(int i=0;i<s.length();i++){
            char ch = s.charAt(i);
            if(ch!='#'){
                ret.append(ch);
            }else if(ret.length()>0){
                ret.deleteCharAt(ret.length()-1);
            }
        }
        return ret.toString();
    }
}
